package com.qxf.util;

import java.security.MessageDigest;

public class MD5 {
	
	public MD5() {
	}
	/**
	 * encryption method
	 * @param strSrc
	 * @return
	 */
	public static String Encrypt(String strSrc) {
		MessageDigest md = null;
		String strDes = null;
		byte b[] = strSrc.getBytes();
		try {
			md = MessageDigest.getInstance("MD5");
			md.update(b);
			strDes = MD5.byte2Hex(md.digest());
		} catch (Exception e) {
			// TODO: handle exception
			return null;
		}
		return strDes;
	}
	/**
	 * byte to hex
	 * @param bts
	 * @return
	 */
	private static String byte2Hex(byte bts[]) {
		String des = "";
		String tmp = null;
		for(int i=0;i<bts.length;i++) {
			tmp = Integer.toHexString(bts[i] & 0xff);
			if (tmp.length()==1) 
				des = (new StringBuffer()).append(des).append("0").toString();
			des = (new StringBuffer()).append(des).append(tmp).toString();
		}
		return des;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(Encrypt("admin"));
	}
}